package App.Config;

import App.Job.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * Created by xw on 2019/5/15.
 */
@Configuration
public class SpringBootScheduleHost {

    @Autowired
    private TaskReminderJobNormal _taskJobNormal;

    @Autowired
    private TaskReminderJobImprove _taskJobImprove;

    @Autowired
    private AuthJobImprove _authJob;

    @Autowired
    private Task24HourJob _task24Hour;

    @Autowired
    private ScheduleConifg _scheduleConfig;

    @Autowired
    private LawyerMessageJob _lawyerMessage;

    @Autowired
    private TaskClearChatGroupJob taskClearChatGroupJob;

    //任务到期提醒,每分钟执行一次 正点提醒
    @Scheduled(cron = "0 0/1 * * * ?")
    public void taskReminderSchedule() {
        if (_scheduleConfig.getIsactive()) {
            _taskJobNormal.execute();
        }
    }
//    @Scheduled(cron = "0 0 0 * * ?")
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void taskClearChatGroupJob() {
        if (_scheduleConfig.getIsactive()) {
            taskClearChatGroupJob.execute();
        }
    }

    //任务到期提醒,每分钟执行一次 提前提醒
    @Scheduled(cron = "0 0/1 * * * ?")
    public void taskReminderScheduleImprove() {
        if (_scheduleConfig.getIsactive()) {
            _taskJobImprove.execute();
        }
    }

    //审批通过,每小时执行一次
    @Scheduled(cron = "0 0 */1 * * ?")
    public void authSchedule() {
        if (_scheduleConfig.getIsactive()) {
            _authJob.execute();
        }
    }

    //24小时未完成任务，每一分钟执行一次
    @Scheduled(cron = "0 0/1 * * * ?")
    public void Task24HourAlert() {
        if (_scheduleConfig.getIsactive()) {
            _task24Hour.execute();
        }
    }

    //下午四点发送消息给律师
    @Scheduled(cron = "0 0 16 * * ?")
    public void LawerAlert() {
        if (_scheduleConfig.getIsactive()) {
            _lawyerMessage.execute();
        }
    }
}
